﻿namespace Away.IdentityServer.Core.Api;

public static class ApiResourceApi
{
    /// <summary>
    /// API资源管理接口
    /// </summary>
    public static IEndpointRouteBuilder MapApiResourceApi(this IEndpointRouteBuilder endpoint)
    {
        endpoint.MapGet("/api/resource", Page);
        endpoint.MapPost("/api/resource", Save);
        endpoint.MapDelete("/api/resource", Remove);
        return endpoint;
    }

    /// <summary>
    /// API资源分页列表
    /// </summary>
    private static IResult Page([AsParameters] ApiResourceSearch search, IApiResourceService service)
    {
        return service.Page(search);
    }

    /// <summary>
    ///  添加、编辑API资源
    /// </summary>
    private static IResult Save([FromBody] ApiResource model, IApiResourceService service)
    {
        service.Save(model);
        return ApiResult.Ok();
    }

    /// <summary>
    /// 删除API资源
    /// </summary>
    private static IResult Remove([FromBody] List<int> ids, IApiResourceService service)
    {
        service.Remove(ids);
        return ApiResult.Ok();
    }
}